<?php

namespace app\api\controller;

use app\common\controller\ApiController;
use app\common\lib\Show;
use EasyAdmin\upload\Uploadfile;
use think\response\Json;

class Upload extends ApiController
{
    public function upload(){
        $file=$this->request->file('file');
        $uploadConfig = sysconfig('upload');
        try {
            $upload = Uploadfile::instance()
                ->setUploadType($uploadConfig['upload_type'])
                ->setUploadConfig($uploadConfig)
                ->setFile($file)
                ->save();
        } catch (\Exception $e) {
            return Show::error([],$e->getMessage());
        }
        if (!$upload['save']) {
            return Show::error([],$upload['msg']);
        }
        return Show::success(['url' => $upload['url']],$upload['msg']);
    }
}